package com.smart.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.smart.model.Community;
import com.smart.service.CommunityService;

@Controller
public class CommunityController {
	@RequestMapping(value="/wechat/get_community_list", method = RequestMethod.POST)
    public void getCommunityList(HttpServletRequest req,HttpServletResponse resp)
    {
		System.out.println("getCommunityList method start....");
		CommunityService communitySer=new CommunityService();
		List<Community> communityList=communitySer.getCommunityList();
		String jsonStr=JSONArray.fromObject(communityList).toString();
		PrintWriter out=null;
		try {
			out=resp.getWriter();
			System.out.println(jsonStr);
			out.print(jsonStr);
		} catch (IOException e) {
			e.printStackTrace();
		}
		finally
		{
			if(out!=null) out.close();
		}
		System.out.println("getCommunityList method finish...");
    }
}
